<?php
/**
 *  友情链接模型类
 */
namespace app\admin\model;
use think\Model;
class Links extends Model
{
	protected $name = 'link';
    // 获取友情链接列表
    public function getList($UrlParam,$PageCount)
    {
        return $this
            ->order('gid asc,sorting asc,id asc')
            ->paginate($PageCount,false,['query' => $UrlParam]);
    }

    // 查找友情链接
    public function findLink($UrlParam,$PageCount)
    {
       $Where = array();
		if(!empty($UrlParam['field'])) $Where['a.title']=['like','%'.trim($UrlParam['keyword']).'%'];
        return $this
            ->where($Where)
            ->order('gid asc,sorting asc,id asc')
            ->paginate($PageCount,false,['query' => $UrlParam]);
    }

    // 获取友情链接详情
    public function getLink($id)
    {
        return $this->where("id=$id")
            ->find();
    }

    // 获取分组
    public function getGid()
    {
        return $this->Distinct(true)
            ->order('gid')
            ->column('gid');
    }

    // 获取最大分组值
    public function getMaxGid()
    {
        return $this->max('gid');
    }

    // 添加友情链接
    public function addLink(array $data)
    {
        return $this->insert($data);
    }

    // 删除友情链接
    public function delLink($id)
    {
        return $this->where("id=$id")
            ->delete();
    }

    // 修改友情链接
    public function modLink($id, $data)
    {
        return $this
            ->where("id=$id")
            ->update($data);
    }
}